console.log("i'm login register");


// (function ($) {
//     $(document).ready(function () {
//         CAKE.passport.signUpForm('#sign-up-form');
//     });
// })(jQuery);
// var bannerHeight = $(window).height() - 80;
// var bannerWidth = $(window).width();
// $('.login-background').css('height', bannerHeight);
// if (bannerWidth <= 1400) {
//     $(".content-box").css('width', bannerWidth);
//     $('.form-login-box').css('right', '100px');
// } else {
//     $(".content-box").css('width', '1200px');
//     $('.form-login-box').css('right', '0');
// }
// $('#birthday').datepicker({
//     dateFormat: 'yy-mm-dd',
//     changeMonth: true,
//     changeYear: true,
//     defaultDate: '1990-01-01',
//     yearRange: 'c-20:c+20'
// });




      var register = document.getElementById("register");
      var form = document.getElementById("register_form");
      var userIpt = document.getElementById("username");
      var pwdIpt = document.getElementById("password");
      var alert = document.querySelector(".alert");

      // console.log(alert);
      // 该变量表示是否已经发送了请求;
      var loading = false;
      // 阻止表单默认事件;
      form.onsubmit = function(evt){
            var e = evt || window.event;
            e.preventDefault();
      }
      // 获取数据发送请求;
      register.onclick = function(evt){
            if(loading) return false;
            var username = userIpt.value;
            var password = pwdIpt.value;

            loading = true;
            register.disabled = "disabled";
            register.innerHTML = "loading...";
            xhrPost("../interface/register.php",{
                  username ,
                  password 
            })
            .then((res)=>{
                  console.log(res);
                  loading = false;
                  register.removeAttribute("disabled");
                  register.innerHTML = "注册";

                  // 注册信息处理;
                  res = JSON.parse(res);
                  if(res.statu === "success"){
                        showInfo("success","恭喜!注册成功，我们三秒钟之后会为您跳转到登陆界面!");
                        setTimeout( a => {
                              // 存cookie;

                              cookie("tocken",res.password,{
                                    expires : 20,
                                    path :"/"
                              });
                              cookie("username",username,{
                                    expires : 20,
                                    path :"/"
                              });

                              location.href = "./login.html";
                        },3000)
                  }else if(res.statu === "error"){
                        showInfo("error" , res.errorType)
                  }
                  
            })
      }

      function showInfo(type,text){
            var children = alert.children[0];
            // 1. 改变元素的 className ;
            if(type === "success"){
                  alert.className = "alert alert-success"
            }else if(type === "error"){
                  alert.className = "alert alert-danger"
            }
            // 2. 显示内容;
            children.innerHTML = text;
            alert.style.display = "block";

            setTimeout(()=>{
                  alert.style.display = "none";
            },3000)
      }
      
      

